/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package proy1sistdistribuidos.modelo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 *
 * @author Carlos Diaz Maya, Juan Felipe Garcia
 */
public class HiloServidorSocketServer extends Thread {
    private Socket socket;

    public HiloServidorSocketServer(Socket accept) {
        super("HiloServidorSocketServer"+System.currentTimeMillis());
        this.socket = accept;
    }

    public void run() {
        try {
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
            BufferedReader in = new BufferedReader(
					new InputStreamReader(
					socket.getInputStream()));
            String entrada, salida;
            ProtocoloServidorSocketEstados plds = new ProtocoloServidorSocketEstados();

            while ((entrada = in.readLine()) != null) {
		salida = plds.procesarEntrada(entrada);
		out.println(salida);
		if (salida.equals("")){
                    salida = null;
		}
            }

            out.close();
            in.close();
            socket.close();
	} catch (IOException e) {
            e.printStackTrace();
	} catch (Exception e) {
            e.printStackTrace();
	}
    }
}
